package com.demo.aop.pcut.stat;

import org.aopalliance.aop.Advice;
import org.springframework.aop.Advisor;
import org.springframework.aop.Pointcut;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;

/**
 * 描述：静态切入点
 *
 * @author lida
 * @time 2019/10/23 11:57
 */
public class StaticPointcutInterceptorDemo {

	public static void main(String[] args) {
		GoodPianist gp = new GoodPianist();
		BadPianist bp = new BadPianist();

		//将通知和切入点结合成Advisor,下面的写法都可以
		//SimpleAdvice simpleAdvice = new SimpleAdvice();
		Advice simpleAdvice = new SimpleAdvice();
		//StaticPointcut staticPointcut = new StaticPointcut();
		StaticPointcut staticPointcut = new StaticPointcut();
		Advisor advisor = new DefaultPointcutAdvisor(staticPointcut, simpleAdvice);

		ProxyFactory pf = new ProxyFactory();
		pf.addAdvisor(advisor);
		pf.setTarget(gp);

		GoodPianist goodPianist = (GoodPianist) pf.getProxy();
		goodPianist.sing();

		pf = new ProxyFactory();
		pf.addAdvisor(advisor);
		pf.setTarget(bp);

		BadPianist badPianist = (BadPianist) pf.getProxy();
		badPianist.sing();
	}
}
